#!/usr/bin/env python3

import json
import sys
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('-e', '--extract', action='store_true')
parser.add_argument('-s', '--store', action='store_true')
parser.add_argument('library', type=str)
parser.add_argument('postscript', type=str)
args = parser.parse_args()

assert args.extract or args.store and not (args.extract and args.store)

with open(args.library) as f:
  lib = json.load(f)

if args.extract:
  with open(args.postscript, 'w') as f:
    f.write(lib['config']['preferences']['postscript'])

else:
  with open(args.postscript) as f:
    lib['config']['preferences']['postscript'] = f.read()

  with open(args.library, 'w') as f:
    json.dump(lib, f, indent='  ')
